/**
 * 
 */
package ptvv;

/**
 * @author dkz
 * 
 */
public class StatesRunthrough extends DefaultAutomata {
	// variables needed for computation
	String message;

	public StatesRunthrough(States2 destination, Thread dest) {
		internalState = InternalStates.Starting;
		logger = Trace.getLogger();
		this.setName("First");
		outputPort = new OutputPort(destination, dest);

	}

	public void starting() throws InterruptedException {

		eventQueue.take();
		// System.out.println(item);

		this.internalState = InternalStates.Ready;
	}

	public void ready() throws InterruptedException {
		message = inputPort.take();
		this.internalState = InternalStates.Running;
	}

	public void running() throws InterruptedException {
		message += " done";
		// System.out.println("sleeping..");
		// System.out.println("awake");
		this.internalState = InternalStates.Suspended;
	}

	public void suspended() throws InterruptedException {
		this.internalState = InternalStates.End;

	}

	public void end() {
		// System.out.println("end");
		logger.log("output: " + this.getName() + ": " + message);
		outputPort.destAutomata.addInput(message);
		// System.out.println(outputPort.destination.internalState);
		outputPort.destThread.interrupt();

		// System.out.println(outputPort.destination.isInterrupted());

		// outputPort.destination.addEvent("START");
		this.internalState = InternalStates.Dead;

	}

	public void dead() {
		this.internalState = InternalStates.ReallyDead;
		// this.internalState = InternalStates.Start;

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}
